package org.example.module.controller.auth;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.module.common.Response;
import org.example.module.service.AuthService;
import org.example.module.utils.ResponseUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.security.auth.login.LoginException;

/**
 * 认证控制器
 *
 * @author yinjunwu
 */
@Api(tags = {"认证模块"})
@RestController
@RequestMapping("/auth")
public class AuthController {

    private final AuthService authService;

    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    @ApiOperation(value = "登录", notes = "请求登录响应权限令牌")
    @PostMapping("/login")
    public Response<LoginResp> login(@RequestBody @Validated LoginReq req) throws LoginException {
        return ResponseUtils.success(authService.login(req));
    }
}
